package indi.zhifa.recipe.bailan.busy.service.game.impl;

import indi.zhifa.recipe.bailan.busy.appproperty.AppProperty;
import indi.zhifa.recipe.bailan.busy.dbgen.battle.dao.service.IBattleDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.battle.entity.po.BattleEntity;
import indi.zhifa.recipe.bailan.busy.dbgen.boss.dao.service.IBossDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.hit.dao.service.IHitDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.player.dao.service.IPlayerBattleDayDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.player.dao.service.IPlayerScoreDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.player.dao.service.IUserDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.player.entity.po.UserEntity;
import indi.zhifa.recipe.bailan.busy.dbgen.sysdata.dao.service.ISysDataDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.union.dao.service.IUnionDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.union.dao.service.IUnionScoreDbService;
import indi.zhifa.recipe.bailan.busy.dbgen.union.entity.po.UnionEntity;
import indi.zhifa.recipe.bailan.busy.enums.EConstellation;
import indi.zhifa.recipe.bailan.busy.memo.BossTypeMemo;
import indi.zhifa.recipe.bailan.busy.service.game.IGameService;
import indi.zhifa.recipe.bailan.busy.service.game.entity.BattleInfoVo;
import indi.zhifa.recipe.bailan.busy.service.game.entity.HitResultVo;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RequiredArgsConstructor
public class GameServiceWeiImpl implements IGameService {

    boolean mBattleOn;
    int mYear;
    EConstellation mConstellation;
    int mDay;

    final IBattleDbService mBattleDbService;
    final IUserDbService mUserDbService;
    final IHitDbService mHitDbService;
    final IUnionScoreDbService mUnionScoreDbService;
    final IUnionDbService mUnionDbService;
    final IPlayerScoreDbService mPlayerScoreDbService;
    final IPlayerBattleDayDbService mPlayerBattleDayDbService;
    final IBossDbService mBossDbService;
    final AppProperty mAppProperty;
    final BossTypeMemo mBossTypeMemo;
    final ISysDataDbService mSysDataDbService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void startBattle(int pYear, EConstellation pEConstellation) {
        // #1 检测是否已经开启会战，如果开启则报错
        // #2 同步输入的年、星座、会战开启状态到全局变量和数据库
        // #3 遍历所有公会
        List<UnionEntity> unionEntityList = mUnionDbService.list();
        for (UnionEntity unionEntity : unionEntityList){
            // #4 创建会战
            // #5 创建公会分数实体
            // #6 初始化BOSS
            // #7 遍历所有公会成员
            List<UserEntity> userEntityList = mUserDbService.listByUnionId(unionEntity.getId());
            for(UserEntity userEntity : userEntityList){
                for(int day = 1; day <=6; day ++){
                    for(int hitIdx=1;hitIdx<=3;hitIdx++){
                        // #8 创建刀数据，初始状态Done设置为false
                    }
                    // #10 创建玩家每日数据
                }
                // #9 创建玩家分数数据
            }
        }
    }

    @Override
    public Integer dayPass() {
        // #1 检测是否已经开启会战，如果没开启则报错
        // #2 如果当前天已经是第6天，则结束会战；否则当前天+1
        // #3 同步全局变量
        return mDay;
    }

    @Override
    public HitResultVo hit(Long pPlayerId, Integer pDamage) {
        return null;
    }

    @Override
    public HitResultVo tail(Long pPlayerId) {
        return null;
    }

    @Override
    public BattleInfoVo status(BattleEntity pBattleEntity) {
        return null;
    }

    @Override
    public BattleInfoVo withDraw(Long pUnionId) {
        return null;
    }

    @Override
    public Integer getDay() {
        return null;
    }

    @Override
    public Integer getYear() {
        return null;
    }

    @Override
    public EConstellation getConstellation() {
        return null;
    }

    @Override
    public boolean isBattleOn() {
        return false;
    }
}
